import { getBallZodiac } from "./lhc";

import imgDefault from "@/assets/images/img-avatar-default.jpg";
import jsscImg from "@/assets/images/lottery-logo/jssc.png";
import jssscImg from "@/assets/images/lottery-logo/jsssc.png";
import amlhcImg from "@/assets/images/lottery-logo/amlhc.png";
import xyftImg from "@/assets/images/lottery-logo/xyft.png";
import jsftImg from "@/assets/images/lottery-logo/jsft.png";
import hklhcImg from "@/assets/images/lottery-logo/hklhc.png";
import azxy5Img from "@/assets/images/lottery-logo/azxy5.png";
import azxy10Img from "@/assets/images/lottery-logo/azxy10.png";
import ygsscImg from "@/assets/images/lottery-logo/ygssc.png";
import ygscImg from "@/assets/images/lottery-logo/ygsc.png";
import ygjsscImg from "@/assets/images/lottery-logo/ygjssc.png";
import jnd28Img from "@/assets/images/lottery-logo/jnd28.png";
import dwydh1Img from "@/assets/images/lottery-logo/dwydh1.png";
import dwydh3Img from "@/assets/images/lottery-logo/dwydh3.png";

import jsscText from "@/assets/images/lottery-logo/jsscText.png";
import jssscText from "@/assets/images/lottery-logo/jssscText.png";
import amlhcText from "@/assets/images/lottery-logo/amlhcText.png";
import xyftText from "@/assets/images/lottery-logo/xyftText.png";
import jsftText from "@/assets/images/lottery-logo/jsftText.png";
import hklhcText from "@/assets/images/lottery-logo/hklhcText.png";
import azxy5Text from "@/assets/images/lottery-logo/azxy5Text.png";
import azxy10Text from "@/assets/images/lottery-logo/azxy10Text.png";
import ygsscText from "@/assets/images/lottery-logo/ygsscText.png";
import ygscText from "@/assets/images/lottery-logo/ygscText.png";
import ygjsscText from "@/assets/images/lottery-logo/ygjsscText.png";
import newamlhcText from "@/assets/images/lottery-logo/newamlhcText.png";
import jnd28Text1 from "@/assets/images/lottery-logo/jnd28Text1.png";
import dwydh1Text from "@/assets/images/lottery-logo/dwydh1Text.png";
import dwydh3Text from "@/assets/images/lottery-logo/dwydh3Text.png";

import lhcRule from "@/components/rule/lhc.vue";
import scRule from "@/components/rule/sc.vue";
import sscRule from "@/components/rule/ssc.vue";
import pcddRule from "@/components/rule/pcdd.vue";
import ydhRule from "@/components/rule/ydh.vue";
import { GameCategory } from "@/enums";

// 彩票logo
export function lotteryLogo(code: number) {
  const idObj: Record<number, string> = {
    1: hklhcImg, // 香港六合彩
    2: amlhcImg, // 澳门六合彩
    3: amlhcImg, // 新澳门六合彩
    4: jssscImg, // 极速时时彩
    5: azxy5Img, // 澳洲幸运5
    6: ygsscImg, // 英国时时彩
    7: xyftImg, // 168幸运飞艇
    8: jsftImg, // 极速飞艇
    9: jsscImg, // 极速赛车
    10: azxy10Img, // 澳洲幸运10
    11: ygscImg, // 英国赛车
    12: ygjsscImg, // 英国极速赛车
    13: jnd28Img, // 加拿大28
    15: dwydh1Img, // 运动会
    16: dwydh3Img // 运动会3
  };
  if (idObj[code]) {
    return idObj[code];
  } else {
    return imgDefault;
  }
}

// 彩票文字
export function lotteryText(LotteryId: number) {
  const idObj: Record<number, string> = {
    1: hklhcText, // 香港六合彩
    2: amlhcText, // 澳门六合彩
    3: newamlhcText, // 新澳门六合彩
    4: jssscText, // 极速时时彩
    5: azxy5Text, // 澳洲幸运5
    6: ygsscText, // 英国时时彩
    7: xyftText, // 168幸运飞艇
    8: jsftText, // 极速飞艇
    9: jsscText, // 极速赛车
    10: azxy10Text, // 澳洲幸运10
    11: ygscText, // 英国赛车
    12: ygjsscText, // 英国极速赛车
    13: jnd28Text1, // 加拿大28
    15: dwydh1Text, // 运动会1
    16: dwydh3Text // 运动会3
  };
  if (idObj[LotteryId]) {
    return idObj[LotteryId];
  } else {
    return '';
  }
}

// 获取对应规则
export function getRule(typeId: Enums.GameCategory) {
  if (typeId == GameCategory.lhc) {
    return lhcRule;
  } else if (typeId == GameCategory.sc) {
    return scRule;
  } else if (typeId == GameCategory.ssc) {
    return sscRule;
  } else if (typeId == GameCategory.pcdd) {
    return pcddRule;
  } else if (typeId == GameCategory.ydh) {
    return ydhRule;
  }
}

function checkResult(numbers: number[]) {
  if (numbers.length !== 3) {
    throw new Error("必须提供3个数字");
  }
  // 先对数字进行排序，方便判断顺子
  numbers.sort(function (a, b) {
    return a - b;
  });
  // 判断豹子
  if (+numbers[0] === +numbers[1] && +numbers[1] === +numbers[2]) {
    return "豹子";
  }
  // 判断对子
  if (+numbers[0] === +numbers[1] || +numbers[1] === +numbers[2] || +numbers[0] === +numbers[2]) {
    return "对子";
  }
  // 判断顺子，包括循环顺子
  if (
    (+numbers[1] - +numbers[0] === 1 && +numbers[2] - +numbers[1] === 1) ||
    (+numbers[0] === 0 && +numbers[1] === 1 && +numbers[2] === 9) ||
    (+numbers[0] === 0 && +numbers[1] === 8 && +numbers[2] === 9)
  ) {
    return "顺子";
  }
  // 如果都不符合
  return "";
}

// 计算赛车的总和龙虎
export function scSumLH(numbers: number[]) {
  const sum = numbers[0] + numbers[1];
  let dx = "小";
  let ds = "单";
  if (sum > 11) {
    dx = "大";
  }
  if (sum % 2 == 0) {
    ds = "双";
  }
  const labels = [];
  for (let i = 0; i < 5; i++) {
    if (numbers[i] > numbers[9 - i]) {
      labels.push("龙");
    } else {
      labels.push("虎");
    }
  }

  return {
    sum,
    dx,
    ds,
    labels
  };
}

// 计算时时彩的总和龙虎
export function sscSumLH(numbers: number[]) {
  const sum = numbers.reduce((acc, cur) => acc + cur, 0);
  let dx = "小";
  let ds = "单";
  let lhh = "虎";
  if (sum >= 23) {
    dx = "大";
  }
  if (sum % 2 == 0) {
    ds = "双";
  }
  if (numbers[0] > numbers[4]) {
    lhh = "龙";
  }
  if (numbers[0] == numbers[4]) {
    lhh = "和";
  }
  return { sum, dx, ds, lhh };
}

// 计算 加拿大28
export function pcddSumLH(numbers: number[]) {
  const bds = checkResult(numbers);
  const sum = numbers.reduce((acc, cur) => acc + cur, 0);
  let jdx = "";
  if (sum >= 0 && sum <= 5) {
    jdx = "极小";
  } else if (sum >= 23 && sum <= 27) {
    jdx = "极大";
  }
  let dx = "小";
  let ds = "单";
  let dxds = "小单";
  if (sum >= 14) {
    dx = "大";
    if (sum % 2 == 0) {
      dxds = "大双";
    } else {
      dxds = "大单";
    }
  } else {
    if (sum % 2 == 0) {
      dxds = "小双";
    } else {
      dxds = "小单";
    }
  }
  if (sum % 2 == 0) {
    ds = "双";
  }
  return {
    sum,
    dx,
    ds,
    dxds,
    jdx,
    bds
  };
}

// 计算 六合彩
export function lhcSumLH(numbers: number[]) {
  const zhengma = numbers.slice(0, 6);
  const tema = numbers.slice(-1)?.[0] || 0;
  return {
    zhengma,
    zhengma_sx: zhengma.map(num => getBallZodiac(num)),
    tema,
    tema_sx: tema ? getBallZodiac(tema) : "无",
    tema_dx: tema > 24 ? "大" : "小",
    tema_ds: tema % 2 == 0 ? "双" : "单"
  };
}
